package cn.Mmovie.servlet;

import cn.Mmovie.bean.Auditorium;
import cn.Mmovie.service.AuditoriumService;
import cn.Mmovie.service.impl.AuditoriumServiceImpl;
import cn.Mmovie.util.PageUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminGoToAuditoriumListServlet", value = "/admin/to_auditorium_list")
public class AdminGoToAuditoriumListServlet extends HttpServlet {
    private AuditoriumService auditoriumService=new AuditoriumServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Integer id= Integer.parseInt(request.getParameter("id"));
        Integer pageSize=10;
        Integer pageNo=auditoriumService.getPageNo(id,pageSize);
        if (pageNo==-1){
            request.setAttribute("failMsg","您选择前去修改的放映厅不存在，请重试！");
            request.getRequestDispatcher("/admin/auditorium_in_cinema").forward(request,response);
        }

        if (request.getParameter("id")==null||request.getParameter("id")==""){
            request.setAttribute("failMsg","您未选择需要前去修改的放映厅，请重试！");
            request.getRequestDispatcher("/admin/auditorium_in_cinema").forward(request,response);
            return;
        }
        if (request.getParameter("pageNo")!=null&&request.getParameter("pageNo")!=""){
            pageNo=Integer.parseInt(request.getParameter("pageNo"));
        }
        if (request.getParameter("pageSize")!=null&&request.getParameter("pageSize")!=""){
            pageSize=Integer.parseInt(request.getParameter("pageSize"));
        }

        PageUtil<Auditorium> pageUtil=auditoriumService.page(pageNo,pageSize);
        request.setAttribute("queryedId",id);
        request.setAttribute("page",pageUtil);
        request.getRequestDispatcher("/WEB-INF/page/main/auditorium_list.jsp").forward(request,response);
    }
}
